-
Notifications
You must be signed in to change notification settings - Fork 216
CHECKOUT-9450: Lazy load payment strategies through essential build #2989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
8371880
to
4ed2273
Compare
32cf86e
to
fa6553f
Compare
4fe1d7e
to
baee36d
Compare
"main": "dist/cjs/checkout-sdk.js", | ||
"module": "dist/esm/checkout-sdk.js", | ||
"typings": "dist/types/checkout-sdk.d.ts", | ||
"exports": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change sets up multiple entry points for the package. See https://docs.npmjs.com/cli/v11/configuring-npm/package-json#exports
"commands": [ | ||
"tsc --outDir ../../temp --declaration --emitDeclarationOnly", | ||
"api-extractor run --config api-extractor/checkout-sdk.json & api-extractor run --config api-extractor/checkout-button.json & api-extractor run --config api-extractor/embedded-checkout.json & api-extractor run --config api-extractor/internal-mappers.json", | ||
"find src/generated/integrations -name 'api-extractor.json' | xargs -I {} -P 8 sh -c 'cd \"$(dirname \"{}\")\" && npx api-extractor run --config api-extractor.json'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since each payment integration has is own entry point, e.g.: @bigcommerce/checkout-sdk/integrations/paypal-commerce
, we need to roll up the TS definitions for each one.
defaultPaymentStrategyFactories, | ||
paymentStrategyFactories, | ||
// TODO: Replace once CHECKOUT-9450.lazy_load_payment_strategies experiment is rolled out | ||
// process.env.ESSENTIAL_BUILD ? {} : paymentStrategyFactories, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Payment integration strategies will be excluded from the essential build once the experiment is fully rolled out. During the build phase, TerserJS will remove paymentStrategyFactories
from the bundle output, as it is treated as dead code.
}; | ||
} | ||
|
||
async function createPackageExports({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function generates content like the following:
packages/core/src/generated/integrations/credit-card/index.ts
export { createCreditCardPaymentStrategy } from '../../../../../credit-card-integration/src';
packages/core/src/generated/integrations/paypal-commerce
export { createPayPalCommerceCustomerStrategy, createPayPalCommerceCreditCustomerStrategy, createPayPalCommerceVenmoCustomerStrategy, createPayPalCommerceFastlaneCustomerStrategy } from '../../../../../paypal-commerce-integration/src';
export { createPayPalCommercePaymentStrategy, createPayPalCommerceCreditPaymentStrategy, createPayPalCommerceVenmoPaymentStrategy, createPayPalCommerceAlternativeMethodsPaymentStrategy, createPayPalCommerceCreditCardsPaymentStrategy, createPayPalCommerceRatePayPaymentStrategy, createPayPalCommerceFastlanePaymentStrategy } from '../../../../../paypal-commerce-integration/src';
export { createPayPalCommerceButtonStrategy, createPayPalCommerceCreditButtonStrategy, createPayPalCommerceVenmoButtonStrategy, createPayPalCommerceAlternativeMethodsButtonStrategy } from '../../../../../paypal-commerce-integration/src';
It also generates content for its corresponding api-extractor.json
.
const { Sentry } = window as SentryWindow; | ||
|
||
if (Sentry?.captureMessage) { | ||
Sentry.captureMessage(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the comment, the plan is to start with a soft rollout. We’ll first compare the data passed in from checkout-js
against the existing registered strategies. If everything aligns, we’ll proceed to remove the existing registration.
baee36d
to
9fa9054
Compare
deb8126
to
3ee2141
Compare
3ee2141
to
270403c
Compare
270403c
to
3f76e30
Compare
What/Why?
checkout-sdk-js
currently bundles all payment, shipping, and checkout button strategies for every payment provider, regardless of whether they are enabled by the merchant. This leads to unnecessary code in the main bundle, increasing its size and reducing performance.To address this problem, the following changes are introduced:
@bigcommerce/checkout-sdk/essential
, which excludes all payment, shipping, and checkout button strategies from the bundle.@bigcommerce/checkout-sdk/integrations/*
on the application side and passed intoCheckoutService
only when needed. This enables splitting strategies into separate chunks based on the component that loads them.CHECKOUT-9450.lazy_load_payment_strategies
experiment is active. We will compare the bundled strategies with those passed in from checkout-js and log any discrepancies in Sentry. Once we confirm that all passed-in strategies consistently match the existing ones, we will remove the bundled strategies.Rollout/Rollback
Disable
CHECKOUT-9450.lazy_load_payment_strategies
experimentTesting / Proof
The screenshots below show the improvements after the experiment is fully rolled out and the old code removed.
Before
716kb gzipped size for the initial scripts
After
546kb gzipped size for the initial scripts - ~24% improvement
This screenshot shows that payment methods still load as expected.
This screenshot shows that the error logger works as expected.